import {
	getMenuPermissions
} from "@/network/sys/menu";

import {
	ElMessage
} from 'element-plus';

const DPermissions = {
	state: {
		permissions: '',
	},
	mutations: {
		SET_PERMISSIONS: (state, value) => {
			state.permissions = value;
		}
	},
	actions: {
		// 获取用户信息
		GetPermissions({
			commit,
			state
		}) {
			return new Promise((resolve, reject) => {
				getMenuPermissions().then(res => {
					if (res.code !== 0) {
						return ElMessage.error(res.msg);
					}
					const permissionsTmp = res.data;
				//	console.log(`userTmp:${permissionsTmp}`)
					commit('SET_PERMISSIONS', permissionsTmp);
					resolve(res)
				}).catch(error => {
					reject(error)
				})
			})
		},
		DeletePermissions({
			commit,
			state
		}) {
			commit('SET_PERMISSIONS', '');
		}
	}
}

export default DPermissions